<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        b2b：<el-input v-model="query.b2b" size="small" clearable placeholder="输入b2b搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        型号：<el-input v-model="query.model" size="small" clearable placeholder="输入型号搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        客户：<el-input v-model="query.customer" size="small" clearable placeholder="输入客户搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        在途数量>= <el-input v-model="query.onPassageQuantity" size="small" clearable placeholder="输入在途数量大于等于搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <date-range-picker v-model="query.createTime" class="date-item" />
        <rrOperation />
      </div>
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="600px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="120px">
          <el-form-item label="B2B号">
            <el-input v-model="form.b2b" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="序号">
            <el-input v-model="form.index" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="型号">
            <el-input v-model="form.model" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="采购数量">
            <el-input v-model="form.quantity" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="入库数量">
            <el-input v-model="form.godownQuantity" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="在途数量">
            <el-input v-model="form.onPassageQuantity" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="期望交付日">
            <el-date-picker v-model="form.expectedDeliveryDate" :disabled="true" type="date" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" :disabled="true" style="width: 370px;"  />
          </el-form-item>
          <el-form-item label="客户">
            <el-input v-model="form.customer" :disabled="true" style="width: 370px;"  />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column type="index" label="序号" :index="indexMethod" />
        <el-table-column prop="b2b" label="B2B号" />
        <!-- <el-table-column prop="index" label="序号" />  -->
        <el-table-column prop="purchaseAttribute" label="采购性质" />
        <el-table-column prop="model" label="型号" />
        <el-table-column prop="originalQuantity" label="原采购数量" />
        <el-table-column prop="quantity" label="采购数量" />
        <el-table-column prop="godownQuantity" label="入库数量" />
        <el-table-column prop="onPassageQuantity" label="在途数量" />
        <!-- <el-table-column prop="expectedDeliveryDate" label="期望交付日" /> -->
        <!-- <el-table-column prop="remark" label="备注" /> -->
        <el-table-column prop="customer" label="客户" />
        <el-table-column prop="initBy" label="请购人" />
        <el-table-column prop="createTime" label="创建日期" />
        <el-table-column v-if="checkPer(['admin','purchaseData:edit','purchaseData:del'])" label="操作" width="150px" align="center">
          <template slot-scope="scope">
            <el-button v-if="scope.row.godownQuantity<scope.row.quantity" v-permission="['admin','purchaseData:edit']" size="mini" style="margin-right: 3px;" type="text" @click="crud.toEdit(scope.row)">修改</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudPurchaseData from '@/api/purchaseData'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
// import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker'

const defaultForm = { id: null, b2b: null, index: null, model: null, quantity: null, expectedDeliveryDate: null, remark: null, customer: null, createBy: null, updateBy: null, createTime: null, updateTime: null }
export default {
  name: 'PurchaseData',
  components: { pagination, crudOperation, rrOperation, DateRangePicker },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '采购数据', url: 'api/purchaseData', idField: 'id', sort: 'id,desc', crudMethod: { ...crudPurchaseData }})
  },
  data() {
    return {
      permission: {
        add: ['admin', 'purchaseData:add'],
        edit: ['admin', 'purchaseData:edit'],
        del: ['admin', 'purchaseData:del']
      },
      rules: {
      }
    }
  },
  created() {
    this.crud.optShow = {
      add: false,
      edit: false,
      del: false,
      download: true,
      reset: true
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    indexMethod(index){
      return (index + 1) + (this.crud.page.page -1) * this.crud.page.size
    }
  }
}
</script>

<style scoped>

</style>
